var purchaseCourseId = getQueryVariable('pcid');
var type = getQueryVariable('type');
jQuery(document).ready(function() {
	$('#kit-search-more').on('click', function() {
		$('.kit-search-mored').toggle();
	});

	var col = [{
			title: '日期',
			//		field:'reportDate',
			align: 'center',
			valign: 'middle',
			formatter: function(value, row, index) {
				var data = '';
				if(row.reportDate) {
					data = (new Date(row.reportDate).Format('dd/MM/yyyy'));
				}
				return data;
			}
		},

		{
			title: '学员名',
			field: 'enName',
			align: 'center',
			valign: 'middle'
		},
		{
			title: 'Zoom ID',
			field: 'zoomId',
			align: 'center',
			valign: 'middle'
		},
		{
			title: '教材',
			field: 'materialEn',
			align: 'center',
			valign: 'middle'
		},
		{
			title: '课时(小时)',
			field: 'enrolledHours',
			align: 'center',
			// valign: 'middle'
            formatter: function(value, row, index) {
                return (row.enrolledHours / 60.0).toFixed(2);
            }
		},
		{
			title: '剩余(小时)',
			field: 'remainingHours',
			align: 'center',
			// valign: 'middle'
            formatter: function(value, row, index) {
                return (row.remainingHours / 60.0).toFixed(2);
            }
		},
		{
			title: '类型',
			field: 'type',
			align: 'center',
			valign: 'middle'
		},
//		{
//			title: 'Status',
//			field: 'status',
//			align: 'center',
//			valign: 'middle'
//		},
		{
			title: '管理',
			formatter: function(value, row, index) {
				var id = value;
				return '<a href="javascript:;" class="layui-btn layui-btn-sm" onclick="preview(\'' + row.id + '\')">预览</a>';
			} //自定义方法，添加操作按钮

		}
	];

	//------------------------------------------加载列表
	$('#_table').bootstrapTable({
		url:baseUrl+ '/reportViews?purchaseCourseId=' + purchaseCourseId+"&type="+type,
		'method': "GET",
		locale: 'zh-CN',
		detailView: false,
		sidePagination: "server", //服务端处理分页
		striped: true, //隔行变色
		undefinedText: "",
		pagination: true,
		singleSelect: false,
		pageSize: pageList[0],
		cache: false, //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
		pageNumber: 1,
		pageList: pageList,
		search: false, //不显示 搜索框
		uniqueId: "id", //每一行的唯一标识，一般为主键列
		showColumns: false, //不显示下拉框（选择显示的列）
		undefinedText: '',
		columns: col,
		queryParams: function(params) {
			return {
				pageNum: this.pageNumber,
				pageSize: this.pageSize,
				purchaseCourseId: purchaseCourseId,
				sortOrder: params.order
			}
		},

	});

})
var check = function() {

}
var addTR = function() {
	parent.layer.open({
		//				title: false,
		maxmin: true,
		type: 2,
		area: modalArea,
		content: './views/form/TestReportEditPC.html?purchaseCourseId=' + purchaseCourseId,
		btn: ['保存', '取消'],
		yes: function(index, layero) {
			var data = $(layero).find("iframe")[0].contentWindow.callback_save();
			console.log(layero);
			$.ajax({
				url:baseUrl+ '/testReports',
				type: 'POST',
				data: data,
				success: function(data) {
					alert(data.msg);
					parent.layer.close(index);
					$('#_table').bootstrapTable('refresh');
				}
			});
		},
		btn2: function(index, layero) {
			//按钮【按钮二】的回调
			console.log(layero);
			//return false 开启该代码可禁止点击该按钮关闭
		}
	});
}

var addPR = function() {
	parent.layer.open({
		//				title: false,
		maxmin: true,
		type: 2,
		area: modalArea,
		content: './views/form/ProgressReportAdd.html?purchaseCourseId=' + purchaseCourseId,
		btn: ['保存', '取消'],
		yes: function(index, layero) {
			var data = $(layero).find("iframe")[0].contentWindow.callback_save();
			console.log(layero);
			$.ajax({
				url:baseUrl+ '/progressReports',
				type: 'POST',
				data: data,
				success: function(data) {
					alert(data.msg);
					parent.layer.close(index);
					$('#_table').bootstrapTable('refresh');
				}
			});
		},
		btn2: function(index, layero) {
			//按钮【按钮二】的回调
			console.log(layero);
			//return false 开启该代码可禁止点击该按钮关闭
		}
	});
}
var CurriculumScheduleView = function(id, type) {
	var pcid = '';
	if(type == 'Progress Report') {
		$.ajax({
			url:baseUrl+ '/progressReports/getPcUid?progressReportId=' + id,
			type: 'get',
			async: false,
			success: function(data) {
				pcid = data.data;
			}
		})
	} else {

	}
	parent.layer.open({
		//				title: false,
		maxmin: true,
		type: 2,
		area: bigArea,
		content: './views/CurriculumScheduleView.html?pcid=' + pcid,
		btn: ['关闭'],
		btn2: function(index, layero) {
			//按钮【按钮二】的回调
			console.log(layero);
			//return false 开启该代码可禁止点击该按钮关闭
		}
	});
}


var preview = function (id) {
    parent.layer.open({
        maxmin: true,
        type: 2,
        area: modalArea,
        content: './views/form/ProgressReportView.html?id=' + id + "&type=" ,
        btn: ['关闭'],
        yes: function (index, layero) {
            parent.layer.close(index);
            // parent.layer.open({
            //     maxmin: true,
            //     type: 2,
            //     area: modalArea,
            //     content: './views/form/ProgressReportEdit.html?id=' + id, //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
            //     btn: ['Submit', 'Cancel'],
            //     yes: function (index, layero) {
            //         var data = $(layero).find("iframe")[0].contentWindow.callback_save();
            //         console.log(layero);
            //         $.ajax({
            //             url: baseUrl + '/progressReports/id/' + id,
            //             type: 'POST',
            //             data: data,
            //             success: function (data) {
            //                 parent.layer.close(index);
            //                 $('#_table').bootstrapTable('refresh');
            //             }
            //         });
            //     },
            //     btn2: function (index, layero) {
            //         console.log(layero);
            //     }
            // });
        },
        // btn2: function (index, layero) {
        //     console.log(layero);
        // }
    });
}